package com.led.datatype;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

import net.sf.json.JSONObject;

public class DataBasic {
	private static int IDX_ID = 1;
	private static int IDX_IDX_DATAS = 2;
	private static int IDX_INFO = 3;
	
	int id;
	int idx_datas;
	String info;

	public String toJsonStr(){
		JSONObject js = new JSONObject();
		js.put("id", id);
		js.put("idx_datas", idx_datas);
		js.put("info", info);
		return js.toString();
	}

	public DataBasic() {
		
	}
	public DataBasic(JSONObject js) {
		if(js.containsKey("id")){
		   id = js.getInt("id");
		}
		info = js.getString("info");
		idx_datas = js.getInt("idx_datas");
		
	}
	
	@Override
	public String toString() {
		return toJsonStr();
	}
	
	public static LinkedList<DataBasic> getDatas(ResultSet rs){
		LinkedList<DataBasic> loadDatas = new LinkedList<DataBasic>();
		if(null == rs){
			return loadDatas;
		}
		
		try {
			while(rs.next()){
				DataBasic data = new DataBasic();
				data.id = rs.getInt(IDX_ID);
				data.idx_datas = rs.getInt(IDX_IDX_DATAS);
				data.info = rs.getString(IDX_INFO);
				loadDatas.add(data);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return loadDatas;
	}
	
}
